<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户管理</title>
<script type="text/javascript">
	
	function deleteUsers(){
		//获得选中数据对象

		var selectedRows=$("#userinfo").datagrid('getSelections');
		if(selectedRows.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];//要删除的序号组合

		for(var i=0;i<selectedRows.length;i++){
			strIds.push(selectedRows[i].user_id);
		}
		var ids=strIds.join(",");
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
			if(r){
				//ajax提交 delIds

				$.post("deleteUserList",{userids:ids},function(result){
					if(result){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+selectedRows.length+"</font>条数据！");
						$("#userinfo").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	function deleteUser(index){
		//获得选中数据对象

		$('#userinfo').datagrid('selectRow',index);// 关键在这里  

	    var selectedRow=$('#userinfo').datagrid('getSelected'); 
		if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		$.messager.confirm("系统提示","您确认要删掉这条数据吗？",function(r){
			if(r){
				//ajax提交 delIds

				$.post("deleteUser",{user_id:selectedRow.user_id},function(result){
					if(result==1){
						$.messager.alert("系统提示","您已成功删除这条数据！");
						$("#userinfo").datagrid("reload");
					}else{
						$.messager.alert('系统提示',"删除失败");
					}
				},"json");
			}
		});
	}
	//查询符合条件的用户

	function searchUser(){
		$('#userinfo').datagrid('load',{
			user_name:$('#user_name').val(),
			user_id:$('#user_id').val(),
			user_style:$('#user_style').combobox("getValue"),
			user_profession:$('#user_profession').combobox("getValue"),
			user_identity:$('#user_identity').combobox("getValue"),
			user_company:$('#user_company').val(),
			user_email:$('#user_email').val(),
			user_validate:$('#user_validate').combobox("getValue"),
		});
	}
	
	//验证用户
	function AddUserIsOk() {
		var user_id = $('#auser_id').val();
		if (user_id != "") {
			$.ajax({
				type : 'POST',
				url : 'addUserIsOk',
				data : {
					user_id : user_id
				},
				success : function(result) {
					if (result == 0)
					    $('#adduserinfo').html("该手机号码已经存在");
					else
						$('#adduserinfo').html("");
				}
			});
		}
	}
	
	
	
	//增加用户

	function saveUser(){
		$("#add_fm").form("submit",{
			url:"addUser",
			onSubmit:function(){
				
				if($('#adduserinfo').html()=="该手机号码已经存在"){
					$.messager.alert("系统提示","请输入正确手机号码");
					return false;
				}
				if($('#auser_id').val()==""){
					$.messager.alert("系统提示","请输入手机号码");
					return false;
				}
				if(!(/^1[0-9]{10}$/.test($('#auser_id').val()))){
			        $.messager.alert("系统提示","手机号码格式不正确");
			        return false;
				}
				if($('#auser_style').combobox("getValue")==""){
					$.messager.alert("系统提示","请选择用户属性");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result==1){
					$.messager.alert("系统提示","保存成功");
					$("#adduser").dialog("close");
					$("#userinfo").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败");
					return;
				}
			}
		});
	}
	
	function formatOper(val,row,index){
		if(row.user_validate_name=='无效'){
			return '<a href="#" onclick="openCheckDialog('+index+')">详情</a>&nbsp;&nbsp;<a href="#" onclick="openUpdateDialog('+index+')">修改</a>';  
		}
		if(row.user_validate_name=='有效'){
	        return '<a href="#" onclick="openCheckDialog('+index+')">详情</a>&nbsp;&nbsp;<a href="#" onclick="openUpdateDialog('+index+')">修改</a>&nbsp;&nbsp;<a href="#" onclick="deleteUser('+index+')">删除</a>';  
		}
	} 
	//关闭对话框

	function closeAddDialog(){
		$("#adduser").dialog("close");
		
	}
	function openUpdateDialog(index){	
	    $("#updateuser").dialog("open");
		$('#userinfo').datagrid('selectRow',index);// 关键在这里  

	    var selectedRow=$('#userinfo').datagrid('getSelected'); 	
	    if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		$("#uuser_id").val(selectedRow.user_id);
		$("#uuser_name").val(selectedRow.user_name);
		$("#uuser_company").val(selectedRow.user_company);
		$("#uuser_email").val(selectedRow.user_email);
		$("#uuser_point").val(selectedRow.user_point);
		$("#uuser_address").val(selectedRow.user_address);
		$("#uuser_remark").val(selectedRow.user_remark);
		$("#uuser_validate").combobox("setValue",selectedRow.user_validate);
		$("#uuser_identity").combobox("setValue",selectedRow.user_identity_id);
		$("#uuser_style").combobox("setValue",selectedRow.user_style_id);
		$("#uuser_profession").combobox("setValue",selectedRow.user_profession_id);
	}
	//增加用户

	function updateUser(){
		$("#update_fm").form("submit",{
			url:"updateUser",
			onSubmit:function(){				
				if($('#uuser_id').val()==""){
					$.messager.alert("系统提示","请输入手机号码");
					return false;
				}
				if(!(/^1[0-9]{10}$/.test($('#uuser_id').val()))){
			        $.messager.alert("系统提示","手机号码格式不正确");
			        return false;
				}
				if($('#uuser_style').combobox("getValue")==""){
					$.messager.alert("系统提示","请选择用户属性");
					return false;
				}
				return $(this).form("validate");
			},
			success:function(result){
				if(result==1){
					$.messager.alert("系统提示","修改成功");
					$("#updateuser").dialog("close");
					$("#userinfo").datagrid("reload");
				}else{
					$.messager.alert("系统提示","修改失败");
					return;
				}
			}
		});
	}
	function openUserAddDialog(){
		$("#adduser").dialog("open");
		$("#adduserinfo").html("");
		$("#auser_id").val("");
		$("#auser_name").val("");
		$("#auser_company").val("");
		$("#auser_email").val("");
		$("#auser_point").val("0");
		$("#auser_address").val("");
		$("#auser_remark").val("");		
		$("#auser_identity").combobox("setValue",1);
		$("#auser_style").combobox("setValue",2);
		$("#auser_profession").combobox("setValue",1);
	}
	function resetAddDialog(){
		$("#adduserinfo").html("");
		$("#auser_id").val("");
		$("#auser_name").val("");
		$("#auser_company").val("");
		$("#auser_email").val("");
		$("#auser_point").val("0");
		$("#auser_address").val("");
		$("#auser_remark").val("");
		$("#auser_identity").combobox("setValue",1);
		$("#auser_style").combobox("setValue",2);
		$("#auser_profession").combobox("setValue",1);
		
	}
	function closeCheckDialog(){
		$("#checkuser").dialog("close");
	}
	function closeUpdateDialog(){
		$("#updateuser").dialog("close");
	}
	closeUpdateDialog
	function openCheckDialog(index){
		$("#checkuser").dialog("open");
		$('#userinfo').datagrid('selectRow',index);// 关键在这里  

	    var selectedRow=$('#userinfo').datagrid('getSelected'); 	
	    if(selectedRow.length==0){
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		$("#cuser_id").val(selectedRow.user_id);
		$("#cuser_name").val(selectedRow.user_name);
		$("#cuser_company").val(selectedRow.user_company);
		$("#cuser_email").val(selectedRow.user_email);
		$("#cuser_point").val(selectedRow.user_point);
		$("#cuser_address").val(selectedRow.user_address);
		$("#cuser_remark").val(selectedRow.user_remark);
		$("#cuser_validate").val(selectedRow.user_validate_name);
		$("#cuser_identity").val(selectedRow.user_identity);
		$("#cuser_style").val(selectedRow.user_style);
		$("#cuser_profession").val(selectedRow.user_profession);
	}
</script>
<link rel="stylesheet" type="text/css"  href="../../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"  href="../../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript" src="../../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin:5px">
	<table id="userinfo" title="用户管理" class="easyui-datagrid" fitColumns="true" striped="true"
	 pagination="true" rownumbers="true" url="getUserList" fit="true" toolbar="#tb">
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="user_name" width="30" align="center">昵称</th>
				<th field="user_id" width="50" align="center">手机号码</th>
				<th field="user_style_id" width="50" align="center" hidden="true">属性id</th>
				<th field="user_style" width="50" align="center">属性名称</th>
				<th field="user_profession" width="50"  align="center">行业</th>
				<th field="user_profession_id" width="50" align="center" hidden="true">行业id</th>
				<th field="user_identity" width="50"  align="center">职业</th>
				<th field="user_identity_id" width="50" align="center" hidden="true">职业id</th>
				<th field="user_company" width="80"  align="center">单位</th>
				<th field="user_email" width="80"  align="center">邮箱</th>
				<th field="user_point" width="20"  align="center">积分</th>
				<th field="user_address" width="100"  align="center">所在地</th>
				<th field="user_validate" width="50"  align="center" hidden="true">是否有效</th>
				<th field="user_validate_name" width="50"  align="center">是否有效</th>
				<th field="user_remark" width="100"  align="center">备注</th>
				<th field="user_lasttime" width="60"  align="center">最后登录时间</th>
				<th field="user_op" width="60"  align="center" formatter="formatOper">操作</th>				
			</tr>
		</thead>
	</table>
	<div id="tb">
		<div>
		<form id="export" method="post">
		    <div>&nbsp;</div>
			&nbsp;昵称：&nbsp;<input type="text" name="user_name" id="user_name" size="20"/>
			&nbsp;手机号：&nbsp;<input type="text" name="user_id" id="user_id" size="15"/>
			&nbsp;属性名称：&nbsp;
			<input id="user_style" class="easyui-combobox" name="user_style" data-options="valueField:'roleid',textField:'rolename',url:'getRoleListN'">
			&nbsp;邮箱：&nbsp;
			<input name="user_email" id="user_email" class="easyui-validatebox" data-options="required:true,validType:'email'">
			&nbsp;是否有效：&nbsp;
			<select class="easyui-combobox" id="user_validate" name="user_validate" editable="false" panelHeight="auto" style="width:100px;">
			    <option value="3">请选择</option>
			    <option value="1">有效</option>
				<option value="2">无效</option>
			</select>&nbsp;&nbsp;&nbsp;&nbsp;
			<div>&nbsp;</div>
			&nbsp;行业：&nbsp;
			<input id="user_profession" class="easyui-combobox" name="user_profession" data-options="valueField:'profession_id',textField:'profession_name',url:'getProfessionList'">
			&nbsp;职业：&nbsp;
			<input id="user_identity" class="easyui-combobox" name="user_identity" data-options="valueField:'identity_id',textField:'identity_name',url:'getIdentityList'">
			
			&nbsp;单位：&nbsp;<input type="text" name="user_company" id="user_company" size="60"/>
			<a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
			<a href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">增加</a>
			<a href="javascript:deleteUsers()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除选中</a>
			<div>&nbsp;</div>
			</form>		
		</div>
	</div>
	
	<div id="adduser" class="easyui-dialog" style="width: 800px;height: 450px;padding: 10px 20px"
		closed="true" buttons="#adduser-buttons" title="新增用户">
		<form id="add_fm" method="post">
		            <div>&nbsp;</div>	
		            &nbsp;昵称： &nbsp;
					<input type="text" name="user_name" id="auser_name" class="easyui-validatebox" data-options="required:true"/>					
					&nbsp;手机号码：&nbsp;
					<input type="text" name="user_id" id="auser_id" class="easyui-validatebox" onblur="AddUserIsOk()" data-options="required:true,validType:'^1(3|4|5|7|8)\d{9}$'"/>
					<label id="adduserinfo"></label>
				    <div>&nbsp;</div>
					&nbsp;属性名称：&nbsp;
					<input id="auser_style" class="easyui-combobox" name="user_style" editable="false" data-options="valueField:'roleid',textField:'rolename',url:'getRoleListN'">    
                    &nbsp;行业：&nbsp;				
					<input id="auser_profession" class="easyui-combobox" name="user_profession" data-options="valueField:'profession_id',textField:'profession_name',url:'getProfessionList'">
			        
                    &nbsp;职业：&nbsp;
					
					<input id="auser_identity" class="easyui-combobox" name="user_identity" data-options="valueField:'identity_id',textField:'identity_name',url:'getIdentityList'">
			        
			        <div>&nbsp;</div>
			        &nbsp;单位：&nbsp;
					<input type="text" name="user_company" id="auser_company" class="easyui-validatebox"/>
					<div>&nbsp;</div>
					&nbsp;邮箱：&nbsp;
					
			        <input name="user_email" id="auser_email" class="easyui-validatebox" data-options="validType:'email'">
			        
			        &nbsp;积分：&nbsp;
					<input type="text" name="user_point" id="auser_point" size="10"/>
					<input type="text" name="user_validate" id="auser_validate" hidden="true" value="1"/>
							
					<div>&nbsp;</div>
					&nbsp;所在地：&nbsp;
					<input type="text" name="user_address" id="auser_address" size="50"/>
					<div>&nbsp;</div>
					&nbsp;备注：&nbsp;
					<textarea name="user_remark" id="auser_remark" rows="3" cols="80"></textarea>	
		</form>
	</div>
	<div id="adduser-buttons">
		<a href="javascript:saveUser()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:resetAddDialog()" class="easyui-linkbutton" iconCls="icon-reset">重置</a>
		<a href="javascript:closeAddDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
	
	
	<div id="updateuser" class="easyui-dialog" style="width: 800px;height: 450px;padding: 10px 20px"
		closed="true" buttons="#updateuser-buttons" title="修改用户信息">
		<form id="update_fm" method="post">
		            <div>&nbsp;</div>						
					&nbsp;手机号码：&nbsp;
					<input type="text" name="user_id" id="uuser_id" class="easyui-validatebox" editable="false" data-options="required:true,validType:'^1(3|4|5|7|8)\d{9}$'"/>
				    &nbsp;昵称： &nbsp;
					<input type="text" name="user_name" id="uuser_name" class="easyui-validatebox" data-options="required:true"/>
					<div>&nbsp;</div>
					&nbsp;属性名称：&nbsp;
					<input id="uuser_style" class="easyui-combobox" name="user_style" editable="false" data-options="valueField:'roleid',textField:'rolename',url:'getRoleListN'">    
                    &nbsp;行业：&nbsp;				
					<input id="uuser_profession" class="easyui-combobox" name="user_profession" editable="false" data-options="valueField:'profession_id',textField:'profession_name',url:'getProfessionList'">
			        
                    &nbsp;职业：&nbsp;
					
					<input id="uuser_identity" class="easyui-combobox" name="user_identity" editable="false" data-options="valueField:'identity_id',textField:'identity_name',url:'getIdentityList'">
			        
			        <div>&nbsp;</div>
			        &nbsp;单位：&nbsp;
					<input type="text" name="user_company" id="uuser_company" class="easyui-validatebox"/>
					
					<div>&nbsp;</div>
					&nbsp;邮箱：&nbsp;
			        <input name="user_email" id="uuser_email" class="easyui-validatebox" data-options="validType:'email'">
			        
			        &nbsp;积分：&nbsp;
					<input type="text" name="user_point" id="uuser_point" size="10"/>
					
					&nbsp;是否有效：&nbsp;
					<select class="easyui-combobox" id="uuser_validate" name="user_validate" editable="false" panelHeight="auto" style="width: 155px">
					    <option value="1">有效</option>
						<option value="2">无效</option>
					</select>
							
					<div>&nbsp;</div>
					&nbsp;所在地：&nbsp;
					<input type="text" name="user_address" id="uuser_address" size="50"/>
					<div>&nbsp;</div>
					&nbsp;备注：&nbsp;
					<textarea name="user_remark" id="uuser_remark" rows="3" cols="80"></textarea>	
		</form>
	</div>
	<div id="updateuser-buttons">
		<a href="javascript:updateUser()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeUpdateDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
	
	<div id="checkuser" class="easyui-dialog" style="width: 800px;height: 450px;padding: 10px 20px"
		closed="true" buttons="#checkuser-buttons" title="用户信息详情">
		<form id="check_fm" method="post">
		            <div>&nbsp;</div>						
					&nbsp;手机号码：&nbsp;
					<input type="text" name="user_id" id="cuser_id" editable="false" class="easyui-validatebox"/>
				    &nbsp;昵称： &nbsp;
					<input type="text" name="user_name" id="cuser_name" editable="false" class="easyui-validatebox"/>
					<div>&nbsp;</div>
					&nbsp;属性名称：&nbsp;
					<input id="cuser_style" name="user_style" editable="false" class="easyui-validatebox">    
                    &nbsp;行业：&nbsp;				
					<input id="cuser_profession" name="user_profession" editable="false" class="easyui-validatebox"/>
                    &nbsp;职业：&nbsp;
					<input id="cuser_identity" name="user_identity" editable="false" class="easyui-validatebox">			        
			        <div>&nbsp;</div>
			        &nbsp;单位：&nbsp;
					<input type="text" name="user_company" id="cuser_company" editable="false"class="easyui-validatebox"/>					
					<div>&nbsp;</div>
					&nbsp;邮箱：&nbsp;
			        <input name="user_email" id="cuser_email" class="easyui-validatebox" editable="false" >
			        
			        &nbsp;积分：&nbsp;
					<input type="text" name="user_point" id="cuser_point" size="10" editable="false" class="easyui-validatebox"/>
					
					&nbsp;是否有效：&nbsp;
					<input type="text" id="cuser_validate" name="user_validate" editable="false" class="easyui-validatebox">
			       						
					<div>&nbsp;</div>
					&nbsp;所在地：&nbsp;
					<input type="text" name="user_address" id="cuser_address" editable="false" size="50"class="easyui-validatebox"/>
					<div>&nbsp;</div>
					&nbsp;备注：&nbsp;
					<textarea name="user_remark" id="cuser_remark" editable="false" rows="3" cols="80" class="easyui-validatebox"></textarea>	
		</form>
	</div>
	<div id="checkuser-buttons">
		
		<a href="javascript:closeCheckDialog()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
	</div>
	
</body>
</html>